package com.starinside.wp.repository;

import com.starinside.wp.domain.AppUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2017/7/18
 * *******************************
 */
@Repository
public interface AppUserRepository extends JpaRepository<AppUser, String> {

    AppUser findByPhone(String phone);

    @Query(value = "SELECT u.* from users u left JOIN userchildren r on u.id = r.uid where r.cid = ?1 and u.phone = ?2 ",nativeQuery = true)
    AppUser findByCidAndPhone(String cid, String phone);

    @Query(value = "SELECT u.* from users u left JOIN userchildren r on u.id = r.uid where r.cid = ?1 group by u.phone", nativeQuery = true)
    List<AppUser> findAllByCid(String cid);
}
